package com.esri.core.geometry;

import com.esri.core.internal.util.d;
import com.github.mikephil.charting.utils.Utils;
import java.io.Serializable;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public abstract class Unit implements Serializable {
    private static final long serialVersionUID = 1;
    protected int mWKID;
    protected double m_factor = -1.0d;
    protected String mName = null;
    protected int mID = -1;
    protected String mDisplayName = null;
    protected String mPluralDisplayName = null;
    protected String mAbbreviation = null;

    /* loaded from: classes.dex */
    public enum UnitType {
        LINEAR,
        ANGULAR,
        AREA,
        UNKNOWN
    }

    static native String nativeGetUnitJson(String str);

    static native double nativeGetUnitToBaseFactor(int i);

    static native int nativeGetUnitType(int i);

    public abstract String getAbbreviation();

    public abstract double getConversionFactor(Unit unit);

    public abstract String getDisplayName();

    public abstract int getID();

    public abstract String getName();

    public abstract String getPluralDisplayName();

    public abstract UnitType getUnitType();

    static {
        GeometryEngine.a();
    }

    /* loaded from: classes.dex */
    public enum EsriUnit {
        UNKNOWN("esriUnknownUnits"),
        INCHES("esriInches"),
        POINTS("esriPoints"),
        FEET("esriFeet"),
        YARDS("esriYards"),
        MILES("esriMiles"),
        NAUTICAL_MILES("esriNauticalMiles"),
        MILLIMETERS("esriMillimeters"),
        CENTIMETERS("esriCentimeters"),
        METERS("esriMeters"),
        KILOMETERS("esriKilometers"),
        DECIMAL_DEGREES("esriDecimalDegrees"),
        DECIMETERS("esriDecimeters");
        
        String a;

        EsriUnit(String str) {
            this.a = str;
        }

        @Override // java.lang.Enum
        public String toString() {
            return this.a;
        }

        public static EsriUnit get(String str) {
            EsriUnit[] values;
            for (EsriUnit esriUnit : values()) {
                if (esriUnit.a.equals(str)) {
                    return esriUnit;
                }
            }
            return null;
        }
    }

    public static Unit create(int i) {
        int nativeGetUnitType = nativeGetUnitType(i);
        if (nativeGetUnitType != 0) {
            if (nativeGetUnitType != 1) {
                if (nativeGetUnitType == 2) {
                    return new AreaUnit(i);
                }
                throw new IllegalArgumentException();
            }
            return new AngularUnit(i);
        }
        return new LinearUnit(i);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static Unit a(String str) {
        try {
            return new CustomUnit(nativeGetUnitJson(str));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static double convertUnits(double d, Unit unit, Unit unit2) {
        return unit.getConversionFactor(unit2) * d;
    }

    public static void convertUnits(double[] dArr, int i, Unit unit, Unit unit2, double[] dArr2) {
        double conversionFactor = unit.getConversionFactor(unit2);
        for (int i2 = 0; i2 < i; i2++) {
            dArr2[i2] = dArr[i2] * conversionFactor;
        }
    }

    public double getUnitToBaseFactor() {
        if (this.m_factor < Utils.DOUBLE_EPSILON) {
            this.m_factor = nativeGetUnitToBaseFactor(this.mWKID);
        }
        return this.m_factor;
    }

    public boolean equals(Object obj) {
        return getClass() == obj.getClass() && getUnitToBaseFactor() == ((Unit) obj).getUnitToBaseFactor();
    }

    public int hashCode() {
        return NumberUtils.hash(getUnitToBaseFactor());
    }

    public String toString() {
        return getClass().getSimpleName() + "[m_factor=" + this.m_factor + ", mWKID=" + this.mWKID + ", mName=" + this.mName + ", mID=" + this.mID + ", mDisplayName=" + this.mDisplayName + ", mPluralDisplayName=" + this.mPluralDisplayName + ", mAbbreviation=" + this.mAbbreviation + "]";
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class CustomUnit extends Unit {
        private static final long serialVersionUID = 1;

        public CustomUnit(String str) throws Exception {
            JsonParser c = d.c(str);
            c.nextToken();
            fromJson(c);
        }

        @Override // com.esri.core.geometry.Unit
        public UnitType getUnitType() {
            return UnitType.UNKNOWN;
        }

        @Override // com.esri.core.geometry.Unit
        public String getName() {
            return this.mName;
        }

        @Override // com.esri.core.geometry.Unit
        public int getID() {
            return this.mID;
        }

        @Override // com.esri.core.geometry.Unit
        public String getDisplayName() {
            return this.mDisplayName;
        }

        @Override // com.esri.core.geometry.Unit
        public String getPluralDisplayName() {
            return this.mPluralDisplayName;
        }

        @Override // com.esri.core.geometry.Unit
        public String getAbbreviation() {
            return this.mAbbreviation;
        }

        @Override // com.esri.core.geometry.Unit
        public double getConversionFactor(Unit unit) {
            return this.m_factor;
        }

        @Override // com.esri.core.geometry.Unit
        public String toString() {
            return "Unit [m_factor=" + this.m_factor + ", mWKID=" + this.mWKID + ", mName=" + this.mName + ", mID=" + this.mID + ", mDisplayName=" + this.mDisplayName + ", mPluralDisplayName=" + this.mPluralDisplayName + ", mAbbreviation=" + this.mAbbreviation + "]";
        }

        public void fromJson(JsonParser jsonParser) throws Exception {
            if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
                return;
            }
            this.mWKID = 0;
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if ("id".equals(currentName)) {
                    this.mID = jsonParser.getIntValue();
                } else if ("name".equals(currentName)) {
                    this.mName = jsonParser.getText();
                } else if ("display_name".equals(currentName)) {
                    this.mDisplayName = jsonParser.getText();
                } else if ("plural_display_name".equals(currentName)) {
                    this.mPluralDisplayName = jsonParser.getText();
                } else if ("abbreviation_name".equals(currentName)) {
                    this.mAbbreviation = jsonParser.getText();
                } else if ("base_factor".equals(currentName)) {
                    this.m_factor = jsonParser.getDoubleValue();
                }
            }
        }
    }
}
